.data
    .align 2
    n:      .word 0
    i:      .word 0
    f:      .word 0
    format: .asciz "%d\n"

.text
    .global main
main:
    @ 提示用户输入一个数
    ldr r0, =format
    ldr r1, =n
    bl printf

    @ 读取输入的'n'
    ldr r0, =n
    ldr r1, =format
    bl scanf

    @ 初始化变量i和f
    ldr r1, =i
    ldr r2, =f
    mov r3, #2     @ 初始化i = 2
    mov r4, #1     @ 初始化f = 1

loop:
    @ 检查是否 i <= n
    ldr r5, [r1]
    ldr r0, =n      @ 将变量n的地址加载到r0
    ldr r6, [r0]    @ 从地址中加载n的值到r6
    cmp r5, r6
    bgt done

    @ 计算 f *= i
    ldr r7, [r2]    @ 将f加载到r7
    mul r7, r7, r5  @ 将f乘以i
    str r7, [r2]    @ 将结果存储在f中

    @ 增加i
    add r3, r3, #1  @ 增加i
    str r3, [r1]    @ 将更新后的i存储到内存中

    @ 重复循环
    b loop

done:
    @ 打印结果
    ldr r0, =format
    ldr r1, [r2]
    bl printf

    @ 退出程序
    mov r0, #0       @ 返回0（退出代码）
    mov r7, #1       @ 退出的系统调用号
    swi 0x0

